<?php


namespace App\Shuixing\Controllers;


use App\Admin\Repositories\WxMenu;
use App\Models\WxNavigation;
use App\Models\WxNavigationPlate;

class ToolController
{
    public function index($id = 0)
    {
        global $__MINI_GLOBAL_IS_ADMIN_SUPER__;
        $__MINI_GLOBAL_IS_ADMIN_SUPER__ = false;

        if ($id == 0) {//全部工具利器导航
            $data = WxNavigationPlate::where('type', 1)
                ->where('state', 0)
                ->orderBy('sort', 'desc')
                ->get(['id', 'name', 'introduce']);
            $data->map(function ($v) {
                $v->list = WxNavigation::where('type', 1)
                    ->where('state', 0)
                    ->where('np_id', $v->id)
                    ->get();
            });
        } else {
            $data = WxNavigationPlate::where('type', 1)
                ->where('state', 0)
                ->where('id', $id)
                ->orderBy('sort', 'desc')
                ->get(['id', 'name', 'introduce']);
            if(_empty_($data)){
                return '<h4 style="text-align: center;margin-top: 100px;">404 无记录</h4>';
            }
            $data->map(function ($v) {
                $v->list = WxNavigation::where('type', 1)
                    ->where('state', 0)
                    ->where('np_id', $v->id)
                    ->get();
            });
        }

        return view('shuixing/tool', ['data' => $data]);
    }
}
